--'------------------------------------------------------------------------------------------------------------------ --' Binder скриптовых зон --' Используется только в одном месте в игре, на арене для того чтобы удалять "отработанные" предметы. --'------------------------------------------------------------------------------------------------------------------ function bind(obj) local ini = obj:spawn_ini() if not ini then return end if ini:section_exist("arena_zone") then if alife() then obj:bind_object(arena_zone_binder(obj)) end end --obj:bind_object(script_zone_binder(obj)) end class "script_zone_binder" function script_zone_binder:__init(obj) super(obj) end function script_zone_binder:net_spawn(se_obj) if not object_binder.net_spawn(self, se_obj) then return false end self.object:set_callback(callback.zone_enter, self.on_enter, self) self.object:set_callback(callback.zone_exit, self.on_exit, self) return true end function script_zone_binder:net_destroy() self.object:set_callback(callback.zone_enter, nil) self.object:set_callback(callback.zone_exit, nil) object_binder.net_destroy(self) end function script_zone_binder:save(packet) object_binder.save(self, packet) end function script_zone_binder:load(packet) object_binder.load(self, packet) end function script_zone_binder:on_enter(zone, obj) --printf("[zone %s] on_enter obj=%s, clsid=%s", zone and zone:name(), obj and obj:name()) end function script_zone_binder:on_exit(zone, obj) --printf("[zone %s] on_exit obj=%s, clsid=%s", zone and zone:name(), obj and obj:name()) end --'-------------------------------------------------------------------------------------------------------------------- --' класс arena_zone_binder. Он контролирует скриптовую зону для smart terrain --'-------------------------------------------------------------------------------------------------------------------- local arena_zones = {} class "arena_zone_binder" (object_binder) function arena_zone_binder:__init(obj) super(obj) self.saved_obj = {} arena_zones[obj:name()] = self end function arena_zone_binder:net_spawn(server_object) if not object_binder.net_spawn(self, server_object) then return false end self.object:set_callback(callback.zone_enter, self.on_enter, self) self.object:set_callback(callback.zone_exit, self.on_exit, self) return true end function arena_zone_binder:net_destroy() self.object:set_callback(callback.zone_enter, nil) self.object:set_callback(callback.zone_exit, nil) object_binder.net_destroy(self) end function arena_zone_binder:purge_items() local sim = alife() for k,v in pairs(self.saved_obj) do local obj = sim:object(k) if (obj) then --printf("release object %s, id %s", obj:name(), k) safe_release_manager.release(obj) end end end --' Сохранение списка зарегистренных объектов function arena_zone_binder:save(packet) --printf("ARENA ZONE SAVE") object_binder.save(self, packet) set_save_marker(packet, "save", false, "arena_zone_binder") local num = #self.saved_obj packet:w_u8(num) for k,v in pairs(self.saved_obj) do packet:w_u16(k) end set_save_marker(packet, "save", true, "arena_zone_binder") end --' Загрузка списка зарегистренных объектов function arena_zone_binder:load(packet) --printf("ARENA ZONE LOAD") object_binder.load(self, packet) set_save_marker(packet, "load", false, "arena_zone_binder") local num = packet:r_u8() for i=1,num do self.saved_obj[packet:r_u16()] = true end set_save_marker(packet, "load", true, "arena_zone_binder") end --' callback на вход в зону. Нужно регистрить все объекты, кроме игрока. --' Так как есть глюк, то этот коллбек вызывается и на вход и на выход из скриптовой зоны function arena_zone_binder:on_enter(zone, obj) if (obj:id() == AC_ID) then return end local cls = obj:clsid() if (IsStalker(nil,cls) or IsMonster(nil,cls) or IsWeapon(nil,cls)) then --printf("arena_zone_binder[zone %s] on_enter obj=%s, clsid=%s", zone:name(), obj:name(), obj:clsid()) self.saved_obj[obj:id()] = true end end function arena_zone_binder:on_exit(zone, obj) self.saved_obj[obj:id()] = nil --printf("arena_zone_binder[zone %s] on_exit obj=%s, clsid=%s", zone:name(), obj:name(), obj:clsid()) end function purge_arena_items(name) local arena_zone = arena_zones[name] if arena_zone then arena_zone:purge_items() end end